<template>
       <div class="my-tag" >
              <input v-if="isShow"
                class="input"
                type="text"
                v-focus
                :value="value"
                placeholder="输入标签"
                @blur="isShow = false"
                @keyup.enter="changeTitle"
              />
              <div class="text" v-else @dblclick="isShow = true">{{ value }}</div>
            </div>
</template>

<script>
export default {
 data(){
    return{
        isShow:false
    }
 },
 props:{
    value:String
 },
 methods:{
    changeTitle(e){
        if(e.target.value.trim() == ''){
            alert('输入内容不能为空')
            return
        }
       this.isShow = false
       this.$emit('input',e.target.value)
    }
 }
}
</script>

<style lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>